package com.accenture.adf.newcodington.module6.activity;

/**
 * 
 * CodingtonEventPass is about buying an entry pass which can be used to attend various events happening in New Codington city
 * 
 * Topic: Activity on Arrays and population of single dimensional array using for loop
 * 
 * Instructions:
 * 1. Use 'CodingtonEventPass_TryIt' as the starting point and add the following changes
 * 2. Change the class name to 'CodingtonEventPass_Activity2' and save file as 'CodingtonEventPass_Activity2'
 * 3. Modify If / Else in checkIfEveningPass() method as below
 * 		a. Modify signature of checkIfEveningPass() method to additionally receive a double parameter
 * 		b. Pass total fare calculated in main() method as a parameter to checkIfEveningPass() method
 * 		c. Declare a double variable for evening additional charge as percentage inside checkIfEveningPass() method
 * 		d. Initialize the evening additional charge as 5
 * 		e. Modify If condition to apply evening additional charge on the total fare received 
 *         as parameter (total fare = total fare * (1 + evening additional charge / 100))
 * 		f. Modify else condition to print "Regular pass incurs no extra charge" to console
 * 		g. Return total fare from checkIfEveningPass() method
 * 4. Change the return type of checkIfEveningPass() to double
 * 5. Capture the return value of total fare from checkIfEveningPass() method and print to console with a message as 'Total fare after checking for evening pass'
 * 6. Modify Switch-Case in checkPassValidity() method as below
 * 		a. Modify signature of checkPassValidity() method to receive a double parameter additionally
 * 		b. Pass total fare returned from checkIfEveningPass() method as a parameter to checkPassValidity() method
 * 		c. Declare a float variable for 3 day discount rate and initialize it with 15
 * 		d. Declare a float variable for 5 day discount rate and initialize it with 25
 * 		e. Modify case 1 to print a message to console as No discount on 1 day pass
 * 		f. Insert a break statement for each case choice
 * 		g. Modify case 3 to calculate new total fare by applying duration discount of 15% on total fare for 3 days
 * 		h. Modify case 5 to calculate new total fare by applying duration discount of 25% on total fare for 5 days
 * 		i. Modify default case to print a message to console as Please choose only 1, 3 or 5
 * 		j. Return total fare from checkPassValidity() method
 * 7. Change the return type of checkPassValidity() to double
 * 8. Remove unused variable result from main() method 
 * 9. Capture the return value of total fare from checkPassValidity() method and print to console with a message as 'Total fare after checking for pass duration'
 * 
 */


public class CodingtonEventPass_Activity2 {
	
	private static final float CHILDREN_FARE = 5; //Try with different values
	private static final float ADULTS_FARE = 8; //Try with different values
	
	public static void main(String[] args){
		
		int noOfChildren;
		int noOfAdults;
		double totalChildrenFare;
		double totalAdultsFare;
		double totalFare;
		
		boolean eveningPass;
		short passValidity;		
				
		noOfChildren = 2; //Try with different values
		noOfAdults = 2;	//Try with different values
		
		totalChildrenFare = noOfChildren * CHILDREN_FARE;
		totalAdultsFare = noOfAdults * ADULTS_FARE;
		
		System.out.println("Hello New Codington Visitors!");
		System.out.println("Total Children Fare: " + totalChildrenFare);
		System.out.println("Total Adults Fare: " + totalAdultsFare);
		
		totalFare = (noOfChildren * CHILDREN_FARE) + (noOfAdults * ADULTS_FARE);
						
		System.out.println("Base Fare: "+totalFare);
		
		eveningPass = true;	//Try changing values true or false
		
		totalFare = checkIfEveningPass(eveningPass, totalFare);
		System.out.println("Total Fare after checking for evening pass: " + totalFare);
		
		passValidity = 3; //Try changing values between 1, 3 or 5
		
		totalFare = checkPassValidity(passValidity, totalFare);
		System.out.println("Total Fare after checking for pass duration: " + totalFare);
		
		int[] travelPass = new int[noOfChildren + noOfAdults];
		
		//Populate single dimensional array
		for(int i=0;i<travelPass.length;i++){
			int passID = i + 100;
			travelPass[i] = passID;
		}
		
		//Print array values
		System.out.println();
		for(int i=0;i<travelPass.length;i++){
			System.out.println(travelPass[i]);
		}
	}
	
	/**
	 * Method checks for evening pass and regular pass and returns appropriate message to main() method
	 * @param eveningPass - flag indicates pass issued is a evening pass or regular pass
	 * @return message - based on evening or regular pass appropriate message will be returned to main() method
	 */
	public static double checkIfEveningPass(boolean eveningPass, double totalFare){		
		double eveningCharge = 5;
		
		if(eveningPass){
			totalFare = totalFare * (1 + eveningCharge / 100);
		}else{
			System.out.println("Regular pass incurs no extra charge.");
		}
		return totalFare;
	}
	
	/**
	 * Method checks for pass duration 1 day, 3 days or 5 days and returns appropriate message to main() method
	 * @param passValidity - validity could be 1 for 1 day pass, 3 for 3 day pass and 5 for 5 day pass
	 * @return - returns appropriate message to main() method based on the duration
	 */
	public static double checkPassValidity(short passValidity, double totalFare){
		float discount3Day = 15;
		float discount5Day = 25;
		
		switch(passValidity){
		
			case 1: System.out.println("No discount on 1 day pass." + totalFare);
					break;
			
			case 3: totalFare = totalFare * 3;					
					totalFare = totalFare - (totalFare * (discount3Day / 100));				
					break;
					
			
			case 5: totalFare = totalFare * 5;
					totalFare = totalFare - (totalFare * (discount5Day / 100));
					break;					
			
			default: System.out.println("Please choose only 1, 3 or 5 for valid pass duration.");	
		}
		return totalFare;
	}
}
